import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:nyh_motorcade_app/config/config.dart';
import 'package:nyh_motorcade_app/http/http_address.dart';
import 'package:nyh_motorcade_app/http/http_manager.dart';
import 'package:nyh_motorcade_app/utils/toast_utils.dart';

class FeedbackController extends GetxController {
  FocusNode feedbackFocus = FocusNode();
  String feedback = "";

  void setFeedback(String feedback) {
    this.feedback = feedback;
    update();
  }

  void submitFeedback() {
    if (feedback.length < 5) {
      if (feedback.length > 0) {
        ToastUtils.toast("请输入不少于5个字的描述");
      }
      return;
    }
    feedbackFocus.unfocus();

    httpManager.post(
      Get.context,
      HttpAddress.FEEDBACK,
      {
        "sourceType": Config.systemType,
        "content": feedback,
      },
      isToast: true,
      isLoadingDialog: true,
      onSuccess: (data) {
        ToastUtils.toast("感谢您的反馈!");
        Get.back();
      },
    );
  }
}
